<?php
require_once 'common.inc.php';
require_once MCC_ROOT.'/include/autochinese.php';
error_reporting(0);
$ip='172.16.18.253';
$port='1753';

//$order_arr=array('uptime'=>array(,,),);
if($action =='search')
{
	
	$tr='@';
	$data='';
	$first=0;
	if(!empty($uptime))
	{
		$gam=50;
		$data=order_build($tr,$uptime,$gam,$first);
		$first=1;
	}
	if(!empty($hotnum))
	{
		$gam=53;
		$data.=order_build($tr,$hotnum,$gam,$first);
		$first=1;
	}
	!empty($corkey)&&$keyarr = explode(' ',$corkey);
	if($keyarr)
	{
		$tmparr = array();
		$flag=0;
		foreach ($keyarr as $vl)
		{
			//vl = mb_convert_encoding($vl,'gbk','utf-8');
			if(function_exists('mb_convert_encoding'))
				$vl = mb_convert_encoding($vl,'gbk','utf-8');
			else
				$vl=$covstr->Convert($vl);
			if(!$vl)
				continue;
			
			if($flag==1)
				$keystr.=';'.$vl;
			else
			{
				$keystr=$vl;
				$flag=1;
			}
		}
	//	print $keystr;
		if($flag==1)
		{
			$gam=52;
			$data.=order_build($tr,$keystr,$gam,$first);
			$first=1;
		}
	}
	if(is_numeric($ifcom)&&$ifcom!=-1)
	{
		if(1==$ifcom) 
		{
			$gam=54;
			$data.=order_build($tr,$ifcom,$gam,$first);
			$first=1;
		}
		if(0==$ifcom) 
		{
			$gam=55;
			$data.=order_build($tr,$ifcom,$gam,$first);
			$first=1;
		}
		
	}
	if(!empty($id)&&intval($id))
	{
		$id=intval($id);
		switch($equal)
		{
			case 1:$equal='>';
				$gam=55;
				$data.=order_build($tr,$id,$gam,$first);break;
			case 2:$equal='=';
				$gam=56;
				$data.=order_build($tr,$id,$gam,$first);break;
			case 3:$equal='<';
				$gam=57;
				$data.=order_build($tr,$id,$gam,$first);break;
		}
		$first=1;
	}
	elseif(empty($id))
	{
		$gam=55;
		$id=1;
		$data.=order_build($tr,$id,$gam,$first);
		$first=1;
	}
	if($hash&&strlen($hash)==40)
	{
		$gam=51;
		$data.=order_build($tr,$hash,$gam,$first);
		$first=1;
	}
	if(1==$alertlevel)
	{
		$gam=58;
		$data.=order_build($tr,$alertlevel,$gam,$first);
		$first=1;
	}
	//print $data;
	if($data)
	{
		$data=$data.'///';
		//print $data;
		
		sendorder($data,$ip,$port);
	}
	//print $data;	
	adminmsg('自动清除成功','autodelbtc.php');
}
else
{
	include_once MCC_ROOT.'/templates/msystem/autodelbtc.htm';
}
/*
function connecthost($host,$port,$btcontent,$timeout=20){
	$fp=fsockopen($host,$port,$errno,$errstr,$timeout);
	//!$fp ?exit('不能连接服务器！！') : exit('suscc!');
	fwrite($fp,$btcontent);
	$serverdata=fgets($fp,1024);
	fclose($fp);
	return $serverdata.'|'.date("Y-m-d H:i:s")."\r\n";
}*/
function order_build($tr,$data,$gam,$first=0)
{
	$add='+';
	if($first==0)
		return sprintf("%d$add%s",$gam,$data);
	else
	    return sprintf("$tr%d$add%s",$gam,$data);
}

function sendorder($data,$ip='',$port='',$timeout='30')
{
	$sock = fsockopen($ip,$port,$errno,$errstr,$timeout);
	if($sock)
	{
		@fputs($sock,$data);
		@fclose($sock);		
	}
}

?>